<?php exit;
$new_postflag_opt = null;//postflag新增结果5种值:null,0,false,true,'0',int
if($pid > 0 && $IsPostFlagEnable){
    $postflagV = fliter_sql(param('threadcreatepostflag', ''),1);//严格过滤
    $postflagReason = param('postflagmarkreason', '');//原因
    if(!empty($postflagV)){
        $new_postflag_opt = 0;
        $selpostflag = $PostFlagCfg['Flags'][$postflagV];
		if(!empty($selpostflag)){
			$PFSubjectFmt = (isset($selpostflag['SubjectFmt'])?$selpostflag['SubjectFmt']:'');
			$ValidPostFlags = &ListValidPostFlags('Auth');//使用权检验
			if(isset($ValidPostFlags[$postflagV]) && $selpostflag['type'] =='mark'){
				$message_txt = null;
				if($postflagV == 'correction' || $postflagV == 'revise')
				{
					$message_txt = strip_html($message,false);
					if(xn_strlen($message_txt)<10)
						$new_postflag_opt = -1;
				}
				if($new_postflag_opt>-1 && empty($selpostflag['AuthGroup']) || $selpostflag['AuthGroup'][0]==0 || in_array($gid,$selpostflag['AuthGroup'])){//验证权限
					if(isset($selpostflag['SubjectFmt']) && !empty($selpostflag['SubjectFmt'])) $PFSubjectFmt = $selpostflag['SubjectFmt'];
					$postflagSubject = FillPostFlagText($PFSubjectFmt,$selpostflag,array('flagname'=>$postflagV,'reason'=>$postflagReason));
					$message_txt = $postflagSubject.'{#'. $message_txt.'#}'.PHP_EOL;
					$inputs = array('pid'=>$pid,$postflagV.'_u'=>$uid,$postflagV.'_g'=>$gid,$postflagV=>$postflagSubject);
					$new_postflag_opt = db_insert($PostFlagTable,$inputs);
					if($new_postflag_opt > 0){//处理纠错与修订
						switch ($postflagV){
							case 'correction':
							case 'revise':
								if(!empty($message_txt)){
								   $revData = db_find_one($theadext_table,array('tid'=>$tid),null,array('reviseerr','aflags'));
								   $rev_haved = false;
								   if(is_array($revData)){
									   $rev_haved = true;
									   $message_txt = $revData['reviseerr'].$message_txt;
								   }
								   if($rev_haved){
									   $new_postflag_opt = db_update($theadext_table,array('tid'=>$tid),array('reviseerr'=>&$message_txt));
								   }
								   else
								   {
									   $new_postflag_opt = db_insert($theadext_table,array('tid'=>$tid,'reviseerr'=>&$message_txt));
								   }
								}
								break;
							default:
								break;
						}
					}
					unset($PFSubjectFmt,$postflagSubject);
				}
			}
		}
    }
}


